import 'package:sainbainu/common/utils/util.dart';

/// 内容列表
class ContentListResponse {
  List<ContentResponse> rows;
  int total;

  ContentListResponse({
    required this.rows,
    required this.total,
  });

  factory ContentListResponse.fromJson(Map<String, dynamic> json) =>
      ContentListResponse(
        total: json['total'] as int,
        rows: (json['rows'] as List)
            .map((e) => ContentResponse.fromJson(e))
            .toList(),
      );
}

/// 内容详情
class ContentResponse {
  int? customerId;
  String? customerName;
  String? avatar;
  int? followFlag;
  int? noteId;
  String? text;
  List<String>? image;
  String? video;
  String? videoCover;
  String? audio;
  int? audioDuration;
  String? link;
  List<String>? contentSort;
  int? groupId;
  String? groupName;
  String? countryName;
  String? provinceName;
  String? cityName;
  String? createTime;
  int? giveFlag;
  int? giveNum;
  int? collectionFlag;
  int? collectionNum;
  int? visitNum;
  int? commentNum;
  int? shareNum;
  String? uniqueTag;
  int officialFlag;
  String? officialName;
  int isMy;

  ContentResponse({
    this.customerId,
    this.customerName,
    this.avatar,
    this.followFlag,
    this.noteId,
    this.text,
    this.image,
    this.video,
    this.videoCover,
    this.audio,
    this.audioDuration,
    this.link,
    this.contentSort,
    this.groupId,
    this.groupName,
    this.countryName,
    this.provinceName,
    this.cityName,
    this.createTime,
    this.giveFlag,
    this.giveNum,
    this.collectionFlag,
    this.collectionNum,
    this.visitNum,
    this.commentNum,
    this.shareNum,
    this.uniqueTag,
    this.officialFlag = 0,
    this.officialName,
    this.isMy = 0,
  });

  factory ContentResponse.fromJson(Map<String, dynamic> json) {
    return ContentResponse(
      customerId: json['customerId'] as int?,
      customerName: json['customerName'] as String?,
      avatar: json['avatar'] as String?,
      followFlag: json['followFlag'] as int?,
      noteId: json['noteId'] as int?,
      text: json['text'] as String?,
      image:
          (json['image'] as List<dynamic>?)?.map((e) => e as String).toList(),
      video: json['video'] as String?,
      videoCover: json['videoCover'] as String?,
      audio: json['audio'] as String?,
      audioDuration: json['audioDuration'] as int?,
      link: json['link'] as String?,
      contentSort: (json['contentSort'] as List<dynamic>?)
          ?.map((e) => e as String)
          .toList(),
      groupId: json['groupId'] as int?,
      groupName: json['groupName'] as String?,
      countryName: json['countryName'] as String?,
      provinceName: json['provinceName'] as String?,
      cityName: json['cityName'] as String?,
      createTime: json['createTime'] as String?,
      giveFlag: json['giveFlag'] as int?,
      giveNum: json['giveNum'] as int?,
      collectionFlag: json['collectionFlag'] as int?,
      collectionNum: json['collectionNum'] as int?,
      visitNum: json['visitNum'] as int?,
      commentNum: json['commentNum'] as int?,
      shareNum: json['shareNum'] as int?,
      uniqueTag: Util.generateRandomString(),
      officialFlag: json['officialFlag'] as int,
      officialName: json['officialName'] as String?,
      isMy: (json['isMy'] as int?) ?? 0,
    );
  }

  Map<String, dynamic> toJson() => {
        'customerId': customerId,
        'customerName': customerName,
        'avatar': avatar,
        'followFlag': followFlag,
        'noteId': noteId,
        'text': text,
        'image': image,
        'video': video,
        'videoCover': videoCover,
        'audio': audio,
        'audioDuration': audioDuration,
        'link': link,
        'contentSort': contentSort,
        'groupId': groupId,
        'groupName': groupName,
        'countryName': countryName,
        'provinceName': provinceName,
        'cityName': cityName,
        'createTime': createTime,
        'giveFlag': giveFlag,
        'giveNum': giveNum,
        'collectionFlag': collectionFlag,
        'collectionNum': collectionNum,
        'visitNum': visitNum,
        'commentNum': commentNum,
        'shareNum': shareNum,
        'officialFlag': officialFlag,
        'officialName': officialName,
        'isMy': isMy,
      };
}
